﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;

using eSYSU.DAL;
using eSYSU.Model;
using eSYSU.IBusiness;

namespace eSYSU.Business
{
    /// <summary>
    /// 校园活动业务类
    /// </summary>
    public class ActivityService
    {
        public ActivityService()
        {
        }


        /// <summary>
        /// 插入一条活动记录
        /// </summary>
        /// <param name="college">活动模型对象</param>
        public static void ActivityInsert(Activity activity)
        {
            IDictionary<string, object> parmsDic = new Dictionary<string, object>();
            parmsDic.Add("@Name", activity.name);
            parmsDic.Add("@ActiType", activity.actiType);
            parmsDic.Add("@Brief", activity.brief);
            parmsDic.Add("@Participant", activity.participant);
            parmsDic.Add("@BeginTime", activity.beginTime);
            parmsDic.Add("@EndTime", activity.endTime);
            parmsDic.Add("@HoldPlace", activity.holdPlace);
            parmsDic.Add("@Keyword", activity.keyword);
            parmsDic.Add("@Poster", activity.poster);
            parmsDic.Add("@Publisher", activity.publisher);
            parmsDic.Add("@PubTime", activity.pubTime);

            SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.StoredProcedure, "proc_Activity_Insert", parmsDic);
        }


        /// <summary>
        /// 获取指定活动的记录（ID为零则获取全部活动记录）
        /// </summary>
        /// <param name="iCollegeID">活动编号（ID为零则获取全部活动记录）</param>
        /// <returns>包含指定活动的记录DataTable对象</returns>
        public static DataTable GetActivities(int activityId)
        {
            if (activityId > -1)
            {
                IDictionary<string, object> parmsDic = new Dictionary<string, object>();
                parmsDic.Add("@_id", activityId);

                return SqlHelper.GetDataTable(SqlHelper.ConnString, CommandType.StoredProcedure, "proc_Activity_Get", parmsDic);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 创建活动海报的缩略图
        /// </summary>
        /// <param name="sOriginalLogoPath">用于生成缩略图的Poster源图地址</param>
        /// <param name="sDestinationLogoPaths">缩略图生成路径（包含扩展名）的字符串数组</param>
        /// <param name="iSize">缩略图的尺寸（与路径数组长度要一致）</param>
        /// <returns>生成结果</returns>
        public static bool CreatePosterThumbnail(string sOriginalPosterPath, string[] sDestinationPosterPaths, int[,] iSize)
        {
            try
            {
                for (int i = 0; i < sDestinationPosterPaths.Length; i++)
                {
                    eSYSU.Common.ImageHelper.CreateThumbnail(sOriginalPosterPath, sDestinationPosterPaths[i], iSize[i, 0], iSize[i, 1]);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}